package kr.co.example.newgugudan;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class RecordClick extends Activity {
	WordDBHelper mHelper;
	EditText mText;
	SQLiteDatabase db;
	ContentValues row;
	Button btn05;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.recorddbsql);

		mHelper = new WordDBHelper(this);
		mText = (EditText)findViewById(R.id.editText);
		btn05=(Button) findViewById(R.id.button1t);
	
		
			
		  /*db = mHelper.getWritableDatabase();  //업데이트
			//SQL 명령으로 갱신
			db.execSQL("UPDATE dic SET han = '소년' WHERE eng = 'boy';");
			mHelper.close();
			*/
			
			db = mHelper.getReadableDatabase();	 
			Cursor cursor;
			// SQL 명령으로 읽기
			cursor = db.rawQuery("SELECT eng, han FROM dic", null);
		
			String Result = "";
			while (cursor.moveToNext()) {
				String a = cursor.getString(0);
				String b = cursor.getString(1);
				Result += (a + "  " + b + "\n");
			}

			if (Result.length() == 0) {
				mText.setText("Empyt Set");
			} else {
				mText.setText(Result);
			}
			cursor.close();
			mHelper.close();
		}
		public void mOnClick(View v){
			switch(v.getId()){
			case R.id.button1t:
			db = mHelper.getWritableDatabase();	
			// SQL 명령으로 삭제
			db.execSQL("DELETE FROM dic;");
			mHelper.close();
			
			}
		}
	}


class WordDBHelper extends SQLiteOpenHelper {
	public WordDBHelper(Context context) {
		super(context, "EngWord.db", null, 1);
	}

	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE dic ( _id INTEGER PRIMARY KEY AUTOINCREMENT, " +
		"a TEXT, b TEXT);");
	}

	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS dic");
		onCreate(db);
	}
}
